package com.itmema.plugin;

import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * Package: com.itmema.plugin
 * Description：http请求
 * Author: huangjian
 * Date:  2020/10/18 13:22
 * Modified By:
 * @author huangjian
 */
public class ContextUtils {
    public static  String getContext(){
        try {
            RestTemplate restTemplate=new RestTemplate();
            ResponseEntity<Map> responseEntity = restTemplate.getForEntity("https://api.nextrt.com/V1/Dutang", Map.class);
            if(responseEntity.getStatusCode().is2xxSuccessful()){
                Map body = responseEntity.getBody();
                List data = (List)body.get("data");
                Map contentStruct = (Map) data.get(0);
                return (String) contentStruct.get("content");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
